<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="shortcut icon" href="data:;base64,iVBORw0KGgo=">
  <style>
    html,
    body {
      margin: 0px;
      overflow: hidden;
      height: 100%;
    }
  </style>
</head>
<body>
  <script type="module">
/* eslint-disable */
// x is compatible with y if y has at least the same members as x
{
    // y's inferred type is { name: string; location: string; }
    let y = { name: "Alice", location: "Seattle" };
    function greet(n) {
        console.log("Hello, " + n.name);
    }
    greet(y); // OK
}
// The source function should has less same parameters
{
    // x = y; // Error
    let items = [1, 2, 3];
    // Don't force these extra parameters
    items.forEach((item, index, array) => console.log(item));
    // Should be OK!
    items.forEach(item => console.log(item));
}
// When comparing the types of function parameters,
// assignment succeeds if either the source parameter is assignable to the target parameter, or vice versa
{
    let EventType;
    (function (EventType) {
        EventType[EventType["Mouse"] = 0] = "Mouse";
        EventType[EventType["Keyboard"] = 1] = "Keyboard";
    })(EventType || (EventType = {}));
    function listenEvent(eventType, handler) {
        /* ... */
    }
    // Unsound, but useful and common
    listenEvent(EventType.Mouse);
    // Undesirable alternatives in presence of soundness
    listenEvent(EventType.Mouse);
    listenEvent(EventType.Mouse);
    // Still disallowed (clear error). Type safety enforced for wholly incompatible types
    // listenEvent(EventType.Mouse, (e: number) => console.log(e));
}
// Enum values from different enum types are considered incompatible
{
    let Status;
    (function (Status) {
        Status[Status["Ready"] = 0] = "Ready";
        Status[Status["Waiting"] = 1] = "Waiting";
    })(Status || (Status = {}));
    let Color;
    (function (Color) {
        Color[Color["Red"] = 0] = "Red";
        Color[Color["Blue"] = 1] = "Blue";
        Color[Color["Green"] = 2] = "Green";
    })(Color || (Color = {}));
    let status = Status.Ready;
    // status = Color.Green;  // Error
}
  </script>
</body>
</html>
